package com.example.wm.SanWar.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.wm.common.Result;
import com.example.wm.common.ResultData;
import com.example.wm.SanWar.entity.GroupTable;
import com.example.wm.SanWar.service.AlliesService;
import com.example.wm.SanWar.service.GroupTableService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Slf4j
@RestController
@RequestMapping("/GourpTableController")
public class GourpTableController {

    @Resource
    private AlliesService alliesService;
    @Resource
    private GroupTableService groupTableService;
    @Transactional
    @PostMapping("/Insert")
    public Result Insert(@RequestBody GroupTable groupTable) {

        boolean b=    groupTableService.save(groupTable);
        if(b){
            Integer id= groupTable.getId();
            return ResultData.success(id);
        }else{
            return ResultData.success("失败");

        }

    }
    @Transactional
    @PostMapping("/search")
    public Result search(@RequestBody GroupTable groupTable) {
        LambdaQueryWrapper<GroupTable>lq=new LambdaQueryWrapper<>();
        lq.eq(GroupTable::getTmid,groupTable.getTmid());
        List<GroupTable> L=groupTableService.list(lq);

        return ResultData.success(L);
    }
    @PostMapping("/Goupsname")
    public Result Goupsname(@RequestBody GroupTable groupTable) {
        LambdaQueryWrapper<GroupTable> lq=new LambdaQueryWrapper<>();
        lq.eq(GroupTable::getCreatename,groupTable.getCreatename());
        lq.eq(GroupTable::getTmid,groupTable.getTmid());

        lq.isNotNull(GroupTable::getName);
        List<GroupTable> list =groupTableService.list(lq);
        Set s=new HashSet<>();
        for(GroupTable e:list){

            s.add(e.getName());
        }

        return ResultData.success(s);
    }


}
